#@Time : 2020/12/10 10:27
#@Author: sl
#@File : user_model.py
# coding: utf-8
from sqlalchemy import BigInteger, Column, DateTime, Integer, text
from sqlalchemy.dialects.mysql import VARCHAR
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata
'''
建表语句：
CREATE TABLE `user_sample` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '用户名',
  `number` int DEFAULT NULL,
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1285923099950198850 DEFAULT CHARSET=utf8 COMMENT='用户表_示例用';

生成model方法：
命令行下
1.pip install sqlacodegen
2.sqlacodegen --tables user_sample mysql+pymysql://用户:密码@地址:3306/库>models.py
'''

class UserSample(Base):
    __tablename__ = 'user_sample'
    __table_args__ = {'comment': '用户表_示例用'}

    id = Column(BigInteger, primary_key=True)
    name = Column(VARCHAR(255), comment='用户名')
    number = Column(Integer)
    create_time = Column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
